package day20171122;

import java.sql.*;

/**
 * Created by Administrator on 2017-11-22.
 */
public class Test {

    public static void main(String[] args) {

        // 加载驱动程序
        Connection connection = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");


            // 参数1： 数据库连接字符串
            // 参数2： 数据库用户名
            // 参数3： 数据库密码
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test?serverTimezone=UTC  ",
                    "root",
                    "sctu123456"
            );


            statement = connection.createStatement();


//            String sql = "SELECT * FROM t_users";
            statement.execute("INSERT INTO t_users(username, password, gender, user_desc) VALUES ('zhangsan', 'abcdefg',1,'Hello!!!')");

//            ResultSet resultSet = statement.executeQuery(sql);
//
//            while(resultSet.next()){
//
//                System.out.println(resultSet.getLong(1));
//                System.out.println(resultSet.getString(2));
//                System.out.println(resultSet.getString(3));
//                System.out.println(resultSet.getInt(4));
//                System.out.println(resultSet.getString(5));
//            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {


            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
